package com.glsc.ngateway.platform.service.itflow.flowstrategy.systemNameApply.taskPostHandler;

import com.glsc.ngateway.common.api.flowable.dto.task.doTaskParam.system.SystemPassParamDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.system.SystemNameApplyTaskFormDataDto;
import com.glsc.ngateway.common.api.flowable.dto.task.formData.system.domainDto.FlowFormSystemNameApplyDto;
import com.glsc.ngateway.common.api.flowable.resp.ResponseSituationDto;
import com.glsc.ngateway.platform.service.FlowCommonService;
import com.glsc.ngateway.platform.service.itflow.flowstrategy.systemNameApply.SystemNameApplyFlowStrategy;
import com.glsc.ngateway.common.base.enums.itflow.ITFlowTaskEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * 流程发起
 * @author xuchang
 */
@Component
public class SNAStep1BeginTaskPostHandlerAudit implements ISystemNameApplyTaskPostHandlerAudit {

    @Resource
    private SystemNameApplyFlowStrategy systemNameApplyFlowStrategy;

    @Autowired
    private SNAStepHandlerHelper handlerHelper;

    @Autowired
    private FlowCommonService flowCommonService;

    /**
     * 退回至起点重新发起时，走审批方法
     */
    @Override
    public void passAfterHandle(@NotNull SystemPassParamDto<FlowFormSystemNameApplyDto, SystemNameApplyTaskFormDataDto> param, String operator) throws Exception {
        systemNameApplyFlowStrategy.saveOrUpdateForm(param.getFlowableFormData(), operator);
        //通知
        ResponseSituationDto processInfo = flowCommonService.getProcessInfo(param.getProcessId());
        FlowFormSystemNameApplyDto formMainData = param.getFlowableFormData().getFormMainData();
        handlerHelper.notify(processInfo, formMainData.getProcessTitle(), formMainData.getFlowCreateOperatorName(), formMainData.getOpName());
    }

    @Override
    public String getTaskDefinitionKey() {
        return ITFlowTaskEnum.SYSTEM_NAME_APPLY_FLOW_BEGIN_TASK.getTaskKey();
    }
}
